package exce1.exce03;

import java.util.ArrayList;
import java.util.Scanner;

//案例3：
//			键盘录入学生的信息， 把学生信息(每个学生都有姓名和年龄)封装为 学生对象， 总共录入5个学生对象，  然后把学生对象 存入到集合中
//				然后遍历集合 打印每一个学生的信息。
public class exre03 {
    public static void main(String[] args) {
        ArrayList<Student> al=new ArrayList<>();
        Student stu=new Student();
        Student stu1 = stuD();
        Student stu2 = stuD();
        Student stu3 = stuD();
        Student stu4 = stuD();
        Student stu5 = stuD();
        al.add(stu1);
        al.add(stu2);
        al.add(stu3);
        al.add(stu4);
        al.add(stu5);
        for (int i = 0; i < al.size(); i++) {
            Student ss = al.get(i);
            System.out.println(ss.getName()+"   "+ss.getAge());
        }
    }

    private static Student stuD() {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入学生姓名：");
        String name =sc.nextLine();
        System.out.println("请输入学生年龄：");
        int age=sc.nextInt();
        return new Student(name,age);
    }
}
class Student{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
